<?php
class UserCheck extends Check {
    public function regCheck(Model &$model,Array $condition=array()) {
        //表单数据验证
        if(self::isNullString($_POST['user'])) {
            $this->flag = false;
            $this->message[] = '用户名不能为空!';
        }
        if(!self::checkNotIllegalStr($_POST['user'])) {
            $this->flag = false;
            $this->message[] = '用户名不能包含[\'、\\、/、<、>、;]等敏感字符!';
        }
        if(self::checkStrLength($_POST['user'],2,'min')) {
            $this->flag = false;
            $this->message[] = '用户名不能少于2位!';
        }
        if(self::checkStrLength($_POST['user'],20,'max')) {
            $this->flag = false;
            $this->message[] = '用户名不能大于20位!';
        }
        if($model->isOne($condition)) {
            $this->flag = false;
            $this->message[] = '用户名称已被占用!';
        }
        if(self::checkStrLength($_POST['pass'],6,'min')) {
            $this->flag = false;
            $this->message[] = '密码不能少于6位!';
        }
        if(!self::checkStrEqual($_POST['pass'],$_POST['notpass'])) {
            $this->flag = false;
            $this->message[] = '两次密码输入必须一致!';
        }
        return $this->flag;
    }


    //登陆验证
    public function loginCheck(Model $model,Array $condition) {
        if(self::isNullString($_POST['user'])) {
            $this->flag = false;      //表示验证不通过
            $this->message[] = '用户名不能为空!';     //错误消息设置
        }
        if(!self::checkNotIllegalStr($_POST['user'])) {
            $this->flag = false;
            $this->message[] = '用户名不能包含[\'、\\、/、<、>、;]等敏感字符!';
        }
        if(self::isNullString($_POST['pass'],6,'min')) {
            $this->flag = false;
            $this->message[] = '密码不能少于六位!';
        }
        if(!$model->isOne($condition)) {
            $this->flag = false;
            $this->message[] = '用户名或者密码错误!';
        }
        return $this->flag;
    }

    public function checkUserName(Model &$model,Array $condition) {
        echo $model->isOne($condition) ? 1 : 2;
    }

    public function ajaxCheckCode(Model $model) {
        echo !self::checkStrEqual($_SESSION['code'],$_POST['code']) ? 1 : 2;
    }


}


?>